package com.foreknow.test;

import com.foreknow.bean.User;
import com.foreknow.db.DBManager;
import com.foreknow.db.JdbcTemplate;
import com.foreknow.mapping.EntityMapping;
import com.foreknow.mapping.MappingFactory;
import com.foreknow.mapping.UserMapping;

import java.sql.Connection;
import java.util.List;

public class tsetjdbc {
    public static void main(String[] args) {
        //1.连接数据库
        DBManager dbManager = DBManager.getInstance();
        Connection conn = dbManager.getConnection();
        JdbcTemplate jdbc = JdbcTemplate.getInstance();
        jdbc.setConnection(conn);
        //调用模板类中的方法
        JdbcTemplate jt = JdbcTemplate.getInstance();
//        EntityMapping mp = new UserMapping();
        MappingFactory mappingFactory = MappingFactory.getmf();
        //从工厂中获取mapping对象
        EntityMapping mp = mappingFactory.getmapping(MappingFactory.USER_MAPPING);
        List<Object> list = jt.query("select * from users",mp);
        for (int i = 0 ;i < list.size();i++){
            User user = (User) list.get(i);
            System.out.println(user.getAdminName());
        }
        int a = jt.update("insert into users(adminName,password) values (?,?)","asd","123456");
        System.out.println(a);
    }
}
